package com.whty.cms.filewps.common.listener;

import com.danga.MemCached.MemCachedClient;
import com.whty.cms.filewps.config.dto.Configure;
import com.whty.cms.filewps.config.service.IConfigureService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class MyServletContextListener implements ApplicationListener<ApplicationReadyEvent>{
	private static final Logger LOG = LoggerFactory.getLogger(MyServletContextListener.class);
	@Autowired
    private IConfigureService configureService;
	
	@Autowired
	private MemCachedClient memCachedClient; 

	@Override
	public void onApplicationEvent(ApplicationReadyEvent event) {
		List<Configure> list = configureService.selectAll();
        for(Configure con : list) {
        	memCachedClient.set(con.getKey(),con.getValue(), 24*60*60*1000);
        }
		LOG.info("缓存成功");
		
	}
}
